From 5badb9bccae803009bde182bf69ee0d02a36b22c Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Mon, 20 Nov 2017 12:13:11 +0100 Subject: cChunkInterface GetBlock, GetBlockMeta, GetBlockTypeMeta use vectors (#4050) --- src/BlockEntities/HopperEntity.cpp | 7 +-- src/Blocks/BlockBed.cpp | 11 ++-- src/Blocks/BlockBed.h | 2 +- src/Blocks/BlockBigFlower.h | 29 ++++++---- src/Blocks/BlockButton.h | 21 ++++--- src/Blocks/BlockCake.h | 2 +- src/Blocks/BlockCauldron.h | 2 +- src/Blocks/BlockComparator.h | 49 ++++++++-------- src/Blocks/BlockDeadBush.h | 2 +- src/Blocks/BlockDoor.cpp | 10 ++-- src/Blocks/BlockDoor.h | 12 ++-- src/Blocks/BlockFarmland.h | 2 +- src/Blocks/BlockFenceGate.h | 2 +- src/Blocks/BlockFire.h | 14 ++--- src/Blocks/BlockHandler.cpp | 6 +- src/Blocks/BlockHandler.h | 2 +- src/Blocks/BlockIce.h | 2 +- src/Blocks/BlockLadder.h | 2 +- src/Blocks/BlockLeaves.h | 2 +- src/Blocks/BlockLever.h | 9 +-- src/Blocks/BlockPiston.cpp | 4 +- src/Blocks/BlockRail.h | 99 +++++++++++++++++---------------- src/Blocks/BlockRedstoneRepeater.h | 2 +- src/Blocks/BlockSlab.h | 4 +- src/Blocks/BlockSnow.h | 6 +- src/Blocks/BlockTallGrass.h | 2 +- src/Blocks/BlockTorch.h | 4 +- src/Blocks/BlockTrapdoor.h | 2 +- src/Blocks/BlockVine.h | 8 +-- src/Blocks/BlockWallSign.h | 2 +- src/Blocks/ChunkInterface.cpp | 24 +++----- src/Blocks/ChunkInterface.h | 7 +-- src/ChunkDef.h | 9 ++- src/ClientHandle.cpp | 2 +- tests/Generating/Stubs.cpp | 2 +- tests/LuaThreadStress/Stubs.cpp | 2 +- tests/SchematicFileSerializer/Stubs.cpp | 2 +- 37 files changed, 179 insertions(+), 190 deletions(-) diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 2fac188b1..e6c2ad546 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -116,9 +116,8 @@ bool cHopperEntity::UsedBy(cPlayer * a_Player) // Instead of marking the chunk as dirty upon chest contents change, we mark it dirty now // We cannot properly detect contents change, but such a change doesn't happen without a player opening the chest first. // The few false positives aren't much to worry about - int ChunkX, ChunkZ; - cChunkDef::BlockToChunk(m_PosX, m_PosZ, ChunkX, ChunkZ); - m_World->MarkChunkDirty(ChunkX, ChunkZ); + cChunkCoords ChunkPos = cChunkDef::BlockToChunk(GetPos()); + m_World->MarkChunkDirty(ChunkPos.m_ChunkX, ChunkPos.m_ChunkZ); return true; } @@ -196,7 +195,7 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) class cHopperPickupSearchCallback { public: - cHopperPickupSearchCallback(const Vector3i & a_Pos, cItemGrid & a_Contents) : + cHopperPickupSearchCallback(Vector3i a_Pos, cItemGrid & a_Contents) : m_Pos(a_Pos), m_bFoundPickupsAbove(false), m_Contents(a_Contents) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index d9199846a..901d7936a 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -17,9 +17,8 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - Vector3i ThisPos(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(ThisPos); Vector3i Direction = MetaDataToDirection(OldMeta & 0x3); if (OldMeta & 0x8) { @@ -55,9 +54,9 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt bool cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { + Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); if (a_WorldInterface.GetDimension() != dimOverworld) { - Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); a_WorldInterface.DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); } else if (!((a_WorldInterface.GetTimeOfDay() > 12541) && (a_WorldInterface.GetTimeOfDay() < 23458))) // Source: https://minecraft.gamepedia.com/Bed#Sleeping @@ -66,7 +65,7 @@ bool cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface } else { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(Coords); if ((Meta & 0x4) == 0x4) { a_Player.SendMessageFailure("This bed is occupied"); @@ -100,13 +99,13 @@ bool cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface VERIFY((Meta & 0x4) != 0x4); // Occupied flag should never be set, else our compilator (intended) is broken PillowDirection = MetaDataToDirection(Meta & 0x3); - if (a_ChunkInterface.GetBlock(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (a_ChunkInterface.GetBlock(Coords + PillowDirection) == E_BLOCK_BED) // Must always use pillow location for sleeping { a_WorldInterface.GetBroadcastManager().BroadcastUseBed(a_Player, a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z); } } - a_Player.SetBedPos(Vector3i(a_BlockX, a_BlockY, a_BlockZ)); + a_Player.SetBedPos(Coords); SetBedOccupationState(a_ChunkInterface, a_Player.GetLastBedPos(), true); a_Player.SetIsInBed(true); a_Player.SendMessageSuccess("Home position set successfully"); diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index a5b256b0b..c66542e7d 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -65,7 +65,7 @@ public: static void SetBedOccupationState(cChunkInterface & a_ChunkInterface, const Vector3i & a_BedPosition, bool a_IsOccupied) { - auto Meta = a_ChunkInterface.GetBlockMeta(a_BedPosition.x, a_BedPosition.y, a_BedPosition.z); + auto Meta = a_ChunkInterface.GetBlockMeta(a_BedPosition); if (a_IsOccupied) { Meta |= 0x04; // Where 0x4 = occupied bit diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index 38d867605..45ba5ac02 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -25,7 +25,7 @@ public: BLOCKTYPE BottomType; if ( (a_Pos.y < 1) || - !a_ChunkInterface.GetBlockTypeMeta(a_Pos.x, a_Pos.y - 1, a_Pos.z, BottomType, a_Meta) || + !a_ChunkInterface.GetBlockTypeMeta(a_Pos - Vector3i(0, 1, 0), BottomType, a_Meta) || (BottomType != E_BLOCK_BIG_FLOWER) ) { @@ -43,7 +43,8 @@ public: virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop) override { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + Vector3i Pos(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(Pos); int AlternateY = a_BlockY; int BottomY = a_BlockY; @@ -57,7 +58,7 @@ public: ++AlternateY; } // also destroy the other block if it has a valid height and is a big flower - if (cChunkDef::IsValidHeight(AlternateY) && a_ChunkInterface.GetBlock(a_BlockX, AlternateY, a_BlockZ) == E_BLOCK_BIG_FLOWER) + if (cChunkDef::IsValidHeight(AlternateY) && a_ChunkInterface.GetBlock({Pos.x, AlternateY, Pos.z}) == E_BLOCK_BIG_FLOWER) { super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, BottomY, a_BlockZ, a_CanDrop); a_ChunkInterface.FastSetBlock(a_BlockX, AlternateY, a_BlockZ, E_BLOCK_AIR, 0); @@ -87,10 +88,11 @@ public: virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + Vector3i BlockPos(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(BlockPos); if (Meta & 0x8) { - Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); + Meta = a_ChunkInterface.GetBlockMeta(BlockPos - Vector3i(0, 1, 0)); } NIBBLETYPE FlowerMeta = Meta & 0x7; @@ -115,7 +117,7 @@ public: { Pickups.Add(E_BLOCK_TALL_GRASS, 2, 2); } - a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ); + a_WorldInterface.SpawnItemPickups(Pickups, BlockPos.x, BlockPos.y, BlockPos.z); } a_Player.UseEquippedItem(); } @@ -129,7 +131,7 @@ public: ) ) { - a_ChunkInterface.SetBlock(a_BlockX, a_BlockY, a_BlockZ, 0, 0); + a_ChunkInterface.SetBlock(BlockPos.x, BlockPos.y, BlockPos.z, 0, 0); } } @@ -153,22 +155,25 @@ public: virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { - NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + Vector3i BlockPos(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(BlockPos); if (OldMeta & 0x8) { // Was upper part of flower - if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) == m_BlockType) + Vector3i LowerPart = BlockPos - Vector3i(0, 1, 0); + if (a_ChunkInterface.GetBlock(LowerPart) == m_BlockType) { - a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(LowerPart, E_BLOCK_AIR, 0); } } else { // Was lower part - if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) == m_BlockType) + Vector3i UpperPart = BlockPos + Vector3i(0, 1, 0); + if (a_ChunkInterface.GetBlock(UpperPart) == m_BlockType) { - a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(UpperPart, E_BLOCK_AIR, 0); } } } diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 079f461ab..2b646c6e8 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -18,11 +18,10 @@ public: virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + Vector3i Pos(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(Pos); - double x(a_BlockX); - double y(a_BlockY); - double z(a_BlockZ); + Vector3d SoundPos(Pos); // If button is already on do nothing if (Meta & 0x08) @@ -34,19 +33,19 @@ public: Meta |= 0x08; a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta, false); - a_WorldInterface.WakeUpSimulators({a_BlockX, a_BlockY, a_BlockZ}); - a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("block.stone_button.click_on", {x, y, z}, 0.5f, 0.6f); + a_WorldInterface.WakeUpSimulators(Pos); + a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("block.stone_button.click_on", SoundPos, 0.5f, 0.6f); // Queue a button reset (unpress) auto TickDelay = (m_BlockType == E_BLOCK_STONE_BUTTON) ? 20 : 30; - a_Player.GetWorld()->ScheduleTask(TickDelay, [x, y, z, a_BlockX, a_BlockY, a_BlockZ, this](cWorld & a_World) + a_Player.GetWorld()->ScheduleTask(TickDelay, [SoundPos, Pos, this](cWorld & a_World) { - if (a_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ) == m_BlockType) + if (a_World.GetBlock(Pos) == m_BlockType) { // Block hasn't change in the meantime; set its meta - a_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07, false); - a_World.WakeUpSimulators({a_BlockX, a_BlockY, a_BlockZ}); - a_World.BroadcastSoundEffect("block.stone_button.click_off", {x, y, z}, 0.5f, 0.5f); + a_World.SetBlockMeta(Pos.x, Pos.y, Pos.z, a_World.GetBlockMeta(Pos) & 0x07, false); + a_World.WakeUpSimulators(Pos); + a_World.BroadcastSoundEffect("block.stone_button.click_off", SoundPos, 0.5f, 0.5f); } } ); diff --git a/src/Blocks/BlockCake.h b/src/Blocks/BlockCake.h index 07973d23c..88125c56b 100644 --- a/src/Blocks/BlockCake.h +++ b/src/Blocks/BlockCake.h @@ -17,7 +17,7 @@ public: virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); if (!a_Player.Feed(2, 0.4)) { diff --git a/src/Blocks/BlockCauldron.h b/src/Blocks/BlockCauldron.h index 9505bc10b..466eb6bcc 100644 --- a/src/Blocks/BlockCauldron.h +++ b/src/Blocks/BlockCauldron.h @@ -23,7 +23,7 @@ public: virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); switch (a_Player.GetEquippedItem().m_ItemType) { case E_ITEM_WATER_BUCKET: diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 52059f8bc..ddbcaa0c2 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -20,7 +20,7 @@ public: virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); Meta ^= 0x04; // Toggle 3rd (addition / subtraction) bit with XOR a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); return true; @@ -70,17 +70,16 @@ public: return ((a_Meta & 0x8) == 0x8); } - inline static Vector3i GetSideCoordinate(const Vector3i & a_Position, NIBBLETYPE a_Meta, bool a_bInverse) + inline static Vector3i GetSideCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta, bool a_bInverse) { - auto Position = a_Position; if (!a_bInverse) { switch (a_Meta) { - case 0x0: Position.x++; break; - case 0x1: Position.z--; break; - case 0x2: Position.x--; break; - case 0x3: Position.z++; break; + case 0x0: a_Position.x++; break; + case 0x1: a_Position.z--; break; + case 0x2: a_Position.x--; break; + case 0x3: a_Position.z++; break; default: { LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta); @@ -93,10 +92,10 @@ public: { switch (a_Meta) { - case 0x0: Position.x--; break; - case 0x1: Position.z++; break; - case 0x2: Position.x++; break; - case 0x3: Position.z--; break; + case 0x0: a_Position.x--; break; + case 0x1: a_Position.z++; break; + case 0x2: a_Position.x++; break; + case 0x3: a_Position.z--; break; default: { LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta); @@ -106,18 +105,17 @@ public: } } - return Position; + return a_Position; } - inline static Vector3i GetRearCoordinate(const Vector3i & a_Position, NIBBLETYPE a_Meta) + inline static Vector3i GetRearCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta) { - auto Position = a_Position; switch (a_Meta) { - case 0x0: Position.z++; break; - case 0x1: Position.x--; break; - case 0x2: Position.z--; break; - case 0x3: Position.x++; break; + case 0x0: a_Position.z++; break; + case 0x1: a_Position.x--; break; + case 0x2: a_Position.z--; break; + case 0x3: a_Position.x++; break; default: { LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta); @@ -126,18 +124,17 @@ public: } } - return Position; + return a_Position; } - inline static Vector3i GetFrontCoordinate(const Vector3i & a_Position, NIBBLETYPE a_Meta) + inline static Vector3i GetFrontCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta) { - auto Position = a_Position; switch (a_Meta) { - case 0x0: Position.z--; break; - case 0x1: Position.x++; break; - case 0x2: Position.z++; break; - case 0x3: Position.x--; break; + case 0x0: a_Position.z--; break; + case 0x1: a_Position.x++; break; + case 0x2: a_Position.z++; break; + case 0x3: a_Position.x--; break; default: { LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta); @@ -146,7 +143,7 @@ public: } } - return Position; + return a_Position; } virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override diff --git a/src/Blocks/BlockDeadBush.h b/src/Blocks/BlockDeadBush.h index 799d3a2f2..68846ff46 100644 --- a/src/Blocks/BlockDeadBush.h +++ b/src/Blocks/BlockDeadBush.h @@ -63,7 +63,7 @@ public: { if (a_CanDrop && (a_Digger != nullptr) && (a_Digger->GetEquippedWeapon().m_ItemType == E_ITEM_SHEARS)) { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); cItems Drops; Drops.Add(m_BlockType, 1, Meta); diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 54a06d5d4..77b18a508 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -18,12 +18,12 @@ cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockType) void cBlockDoorHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); if (OldMeta & 8) { // Was upper part of door - if (IsDoorBlockType(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ))) + if (IsDoorBlockType(a_ChunkInterface.GetBlock({a_BlockX, a_BlockY - 1, a_BlockZ}))) { a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); } @@ -31,7 +31,7 @@ void cBlockDoorHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldIn else { // Was lower part - if (IsDoorBlockType(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))) + if (IsDoorBlockType(a_ChunkInterface.GetBlock({a_BlockX, a_BlockY + 1, a_BlockZ}))) { a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0); } @@ -50,7 +50,7 @@ bool cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterfac UNUSED(a_CursorY); UNUSED(a_CursorZ); - switch (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)) + switch (a_ChunkInterface.GetBlock({a_BlockX, a_BlockY, a_BlockZ})) { default: { @@ -87,7 +87,7 @@ void cBlockDoorHandler::OnCancelRightClick(cChunkInterface & a_ChunkInterface, c UNUSED(a_ChunkInterface); a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); if (Meta & 0x8) { diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 77dc8ca70..7413b180a 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -40,8 +40,8 @@ public: } if ( - !CanReplaceBlock(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)) || - !CanReplaceBlock(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)) + !CanReplaceBlock(a_ChunkInterface.GetBlock({a_BlockX, a_BlockY, a_BlockZ})) || + !CanReplaceBlock(a_ChunkInterface.GetBlock({a_BlockX, a_BlockY + 1, a_BlockZ})) ) { return false; @@ -233,14 +233,14 @@ public: Fails gracefully for (invalid) doors on the world's top and bottom. */ static NIBBLETYPE GetCompleteDoorMeta(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); if ((Meta & 0x08) != 0) { // The coords are pointing at the top part of the door if (a_BlockY > 0) { - NIBBLETYPE DownMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); + NIBBLETYPE DownMeta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY - 1, a_BlockZ}); return static_cast((DownMeta & 0x07) | 0x08 | (Meta << 4)); } // This is the top part of the door at the bottommost layer of the world, there's no bottom: @@ -251,7 +251,7 @@ public: // The coords are pointing at the bottom part of the door if (a_BlockY < cChunkDef::Height - 1) { - NIBBLETYPE UpMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY + 1, a_BlockZ); + NIBBLETYPE UpMeta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY + 1, a_BlockZ}); return static_cast(Meta | (UpMeta << 4)); } // This is the bottom part of the door at the topmost layer of the world, there's no top: @@ -262,7 +262,7 @@ public: /** Sets the door to the specified state. If the door is already in that state, does nothing. */ static void SetOpen(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open) { - BLOCKTYPE Block = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ); + BLOCKTYPE Block = a_ChunkInterface.GetBlock({a_BlockX, a_BlockY, a_BlockZ}); if (!IsDoorBlockType(Block)) { return; diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h index 83a8385c2..09982cd5e 100644 --- a/src/Blocks/BlockFarmland.h +++ b/src/Blocks/BlockFarmland.h @@ -82,7 +82,7 @@ public: } // Check whether we should revert to dirt: - BLOCKTYPE UpperBlock = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ); + BLOCKTYPE UpperBlock = a_ChunkInterface.GetBlock({a_BlockX, a_BlockY + 1, a_BlockZ}); if (cBlockInfo::FullyOccupiesVoxel(UpperBlock)) { a_ChunkInterface.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DIRT, 0); diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index f0af925d1..0044cbc99 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -36,7 +36,7 @@ public: virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); NIBBLETYPE NewMetaData = PlayerYawToMetaData(a_Player.GetYaw()); OldMetaData ^= 4; // Toggle the gate diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index f16347558..ae0df0727 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -55,14 +55,14 @@ public: Takes the X, Y, and Z of the base block; with an optional MaxY for portal border finding */ int FindObsidianCeiling(int X, int Y, int Z, cChunkInterface & a_ChunkInterface, int MaxY = 0) { - if (a_ChunkInterface.GetBlock(X, Y, Z) != E_BLOCK_OBSIDIAN) + if (a_ChunkInterface.GetBlock({X, Y, Z}) != E_BLOCK_OBSIDIAN) { return 0; } for (int newY = Y + 1; newY < cChunkDef::Height; newY++) { - BLOCKTYPE Block = a_ChunkInterface.GetBlock(X, newY, Z); + BLOCKTYPE Block = a_ChunkInterface.GetBlock({X, newY, Z}); if ((Block == E_BLOCK_AIR) || (Block == E_BLOCK_FIRE)) { continue; @@ -92,7 +92,7 @@ public: { for (int checkBorder = FoundObsidianY + 1; checkBorder <= MaxY - 1; checkBorder++) // FoundObsidianY + 1: FoundObsidianY has already been checked in FindObsidianCeiling; MaxY - 1: portal doesn't need corners { - if (a_ChunkInterface.GetBlock(X, checkBorder, Z) != E_BLOCK_OBSIDIAN) + if (a_ChunkInterface.GetBlock({X, checkBorder, Z}) != E_BLOCK_OBSIDIAN) { // Base obsidian, base + 1 obsidian, base + x NOT obsidian -> not complete portal return false; @@ -159,7 +159,7 @@ public: { Dir = 1; // Set assumed direction (will change if portal turns out to be facing the other direction) bool FoundFrameXP = false, FoundFrameXM = false; - for (; ((a_ChunkInterface.GetBlock(X1, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X1, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X1++) // Check XP for obsidian blocks, exempting corners + for (; ((a_ChunkInterface.GetBlock({X1, Y, Z}) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock({X1, Y + 1, Z}) == E_BLOCK_OBSIDIAN)); X1++) // Check XP for obsidian blocks, exempting corners { int Value = FindObsidianCeiling(X1, Y, Z, a_ChunkInterface, MaxY); int ValueTwo = FindObsidianCeiling(X1, Y + 1, Z, a_ChunkInterface, MaxY); // For corners without obsidian @@ -174,7 +174,7 @@ public: } } XZP = X1 - 1; // Set boundary of frame interior - for (; ((a_ChunkInterface.GetBlock(X2, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X2, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X2--) // Go the other direction (XM) + for (; ((a_ChunkInterface.GetBlock({X2, Y, Z}) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock({X2, Y + 1, Z}) == E_BLOCK_OBSIDIAN)); X2--) // Go the other direction (XM) { int Value = FindObsidianCeiling(X2, Y, Z, a_ChunkInterface, MaxY); int ValueTwo = FindObsidianCeiling(X2, Y + 1, Z, a_ChunkInterface, MaxY); @@ -198,7 +198,7 @@ public: { Dir = 2; bool FoundFrameZP = false, FoundFrameZM = false; - for (; ((a_ChunkInterface.GetBlock(X, Y, Z1) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X, Y + 1, Z1) == E_BLOCK_OBSIDIAN)); Z1++) + for (; ((a_ChunkInterface.GetBlock({X, Y, Z1}) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock({X, Y + 1, Z1}) == E_BLOCK_OBSIDIAN)); Z1++) { int Value = FindObsidianCeiling(X, Y, Z1, a_ChunkInterface, MaxY); int ValueTwo = FindObsidianCeiling(X, Y + 1, Z1, a_ChunkInterface, MaxY); @@ -213,7 +213,7 @@ public: } } XZP = Z1 - 1; - for (; ((a_ChunkInterface.GetBlock(X, Y, Z2) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X, Y + 1, Z2) == E_BLOCK_OBSIDIAN)); Z2--) + for (; ((a_ChunkInterface.GetBlock({X, Y, Z2}) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock({X, Y + 1, Z2}) == E_BLOCK_OBSIDIAN)); Z2--) { int Value = FindObsidianCeiling(X, Y, Z2, a_ChunkInterface, MaxY); int ValueTwo = FindObsidianCeiling(X, Y + 1, Z2, a_ChunkInterface, MaxY); diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 1eaef9702..9fc41de76 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -441,7 +441,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, int a_Ne { if ((a_NeighborY >= 0) && (a_NeighborY < cChunkDef::Height)) { - cBlockInfo::GetHandler(a_ChunkInterface.GetBlock(a_NeighborX, a_NeighborY, a_NeighborZ))->OnNeighborChanged(a_ChunkInterface, a_NeighborX, a_NeighborY, a_NeighborZ, a_WhichNeighbor); + cBlockInfo::GetHandler(a_ChunkInterface.GetBlock({a_NeighborX, a_NeighborY, a_NeighborZ}))->OnNeighborChanged(a_ChunkInterface, a_NeighborX, a_NeighborY, a_NeighborZ, a_WhichNeighbor); } } @@ -462,7 +462,7 @@ void cBlockHandler::ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop) { cItems Pickups; - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); if (a_CanDrop) { @@ -621,7 +621,7 @@ bool cBlockHandler::DoesDropOnUnsuitable(void) /* default functionality: only test for height, since we assume full voxels with varying height */ -bool cBlockHandler::IsInsideBlock(const Vector3d & a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) +bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) { return a_Position.y < cBlockInfo::GetBlockHeight(a_BlockType); } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 1638abf8f..d027d3cdc 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -133,7 +133,7 @@ public: /** Tests if a_Position is inside the block where a_Position is relative to the origin of the block Note that this is considered from a "top-down" perspective i.e. empty spaces on the bottom of a block don't matter */ - virtual bool IsInsideBlock(const Vector3d & a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta); + virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta); /** Called when one of the neighbors gets set; equivalent to MC block update. By default drops if position no more suitable (CanBeAt(), DoesDropOnUnsuitable(), Drop()), diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h index b36b95f37..845bb423b 100644 --- a/src/Blocks/BlockIce.h +++ b/src/Blocks/BlockIce.h @@ -31,7 +31,7 @@ public: cEnchantments Enchantments = a_Player.GetInventory().GetEquippedItem().m_Enchantments; if (Enchantments.GetLevel(cEnchantments::enchSilkTouch) == 0) { - BLOCKTYPE BlockBelow = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); + BLOCKTYPE BlockBelow = a_ChunkInterface.GetBlock({a_BlockX, a_BlockY - 1, a_BlockZ}); if (!cBlockInfo::FullyOccupiesVoxel(BlockBelow) && !IsBlockLiquid(BlockBelow)) { return; diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index 27fbed9af..a17cfc1a1 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -101,7 +101,7 @@ public: AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); - return cBlockInfo::IsSolid(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)); + return cBlockInfo::IsSolid(a_ChunkInterface.GetBlock({a_BlockX, a_BlockY, a_BlockZ})); } virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 5cd147fb5..0d7500491 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -74,7 +74,7 @@ public: virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_WhichNeighbor) override { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); // Set 0x8 bit so this block gets checked for decay: if ((Meta & 0x08) == 0) diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 1ec58c534..6750649ae 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -19,12 +19,13 @@ public: virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { + Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); // Flip the ON bit on / off using the XOR bitwise operation - NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08); + NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(Coords) ^ 0x08); - a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); - a_WorldInterface.WakeUpSimulators({a_BlockX, a_BlockY, a_BlockZ}); - a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("block.lever.click", Vector3d(a_BlockX, a_BlockY, a_BlockZ), 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); + a_ChunkInterface.SetBlockMeta(Coords.x, Coords.y, Coords.z, Meta); + a_WorldInterface.WakeUpSimulators(Coords); + a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("block.lever.click", Vector3d(Coords), 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); return true; } diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index c88263d9c..16dd53daf 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -29,7 +29,7 @@ void cBlockPistonHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorld { Vector3i blockPos(a_BlockX, a_BlockY, a_BlockZ); - NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(blockPos.x, blockPos.y, blockPos.z); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(blockPos); // If the piston is extended, destroy the extension as well if (IsExtended(OldMeta)) { @@ -322,7 +322,7 @@ void cBlockPistonHeadHandler::OnDestroyedByPlayer(cChunkInterface & a_ChunkInter Vector3i blockPos(a_BlockX, a_BlockY, a_BlockZ); // Get the base of the piston - NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(blockPos.x, blockPos.y, blockPos.z); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(blockPos); blockPos -= cBlockPistonHandler::MetadataToOffset(OldMeta); BLOCKTYPE Block = a_ChunkInterface.GetBlock(blockPos); diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 9ee891830..98913556a 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -35,8 +35,8 @@ public: ) override { a_BlockType = m_BlockType; - a_BlockMeta = FindMeta(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); Vector3i Pos{ a_BlockX, a_BlockY, a_BlockZ }; + a_BlockMeta = FindMeta(a_ChunkInterface, Pos); return a_Player.GetWorld()->DoWithChunkAt(Pos, [this, Pos, &a_ChunkInterface](cChunk & a_Chunk) { @@ -78,11 +78,12 @@ public: virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_WhichNeighbor) override { - auto Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - auto NewMeta = FindMeta(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); - if (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ) && (Meta != NewMeta)) + Vector3i Pos(a_BlockX, a_BlockY, a_BlockZ); + auto Meta = a_ChunkInterface.GetBlockMeta(Pos); + auto NewMeta = FindMeta(a_ChunkInterface, Pos); + if (IsUnstable(a_ChunkInterface, Pos) && (Meta != NewMeta)) { - a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (m_BlockType == E_BLOCK_RAIL) ? NewMeta : NewMeta | (Meta & 0x08)); + a_ChunkInterface.FastSetBlock(Pos, m_BlockType, (m_BlockType == E_BLOCK_RAIL) ? NewMeta : NewMeta | (Meta & 0x08)); } } @@ -135,33 +136,33 @@ public: return true; } - NIBBLETYPE FindMeta(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + NIBBLETYPE FindMeta(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos) { NIBBLETYPE Meta = 0; char RailsCnt = 0; bool Neighbors[8]; // 0 - EAST, 1 - WEST, 2 - NORTH, 3 - SOUTH, 4 - EAST UP, 5 - WEST UP, 6 - NORTH UP, 7 - SOUTH UP memset(Neighbors, 0, sizeof(Neighbors)); - Neighbors[0] = (IsUnstable(a_ChunkInterface, a_BlockX + 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN)); - Neighbors[1] = (IsUnstable(a_ChunkInterface, a_BlockX - 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST, E_PURE_DOWN)); - Neighbors[2] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ - 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN)); - Neighbors[3] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ + 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_DOWN)); - Neighbors[4] = (IsUnstable(a_ChunkInterface, a_BlockX + 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST, E_PURE_NONE)); - Neighbors[5] = (IsUnstable(a_ChunkInterface, a_BlockX - 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_WEST, E_PURE_NONE)); - Neighbors[6] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ - 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_NONE)); - Neighbors[7] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ + 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_NONE)); - if (IsUnstable(a_ChunkInterface, a_BlockX + 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_EAST)) + Neighbors[0] = (IsUnstable(a_ChunkInterface, a_BlockPos + Vector3i(1, 0, 0)) || !IsNotConnected(a_ChunkInterface, a_BlockPos, BLOCK_FACE_EAST, E_PURE_DOWN)); + Neighbors[1] = (IsUnstable(a_ChunkInterface, a_BlockPos - Vector3i(1, 0, 0)) || !IsNotConnected(a_ChunkInterface, a_BlockPos, BLOCK_FACE_WEST, E_PURE_DOWN)); + Neighbors[2] = (IsUnstable(a_ChunkInterface, a_BlockPos - Vector3i(0, 0, 1)) || !IsNotConnected(a_ChunkInterface, a_BlockPos, BLOCK_FACE_NORTH, E_PURE_DOWN)); + Neighbors[3] = (IsUnstable(a_ChunkInterface, a_BlockPos + Vector3i(0, 0, 1)) || !IsNotConnected(a_ChunkInterface, a_BlockPos, BLOCK_FACE_SOUTH, E_PURE_DOWN)); + Neighbors[4] = (IsUnstable(a_ChunkInterface, a_BlockPos + Vector3i(1, 1, 0)) || !IsNotConnected(a_ChunkInterface, a_BlockPos + Vector3i(0, 1, 0), BLOCK_FACE_EAST, E_PURE_NONE)); + Neighbors[5] = (IsUnstable(a_ChunkInterface, a_BlockPos - Vector3i(1, 1, 0)) || !IsNotConnected(a_ChunkInterface, a_BlockPos + Vector3i(0, 1, 0), BLOCK_FACE_WEST, E_PURE_NONE)); + Neighbors[6] = (IsUnstable(a_ChunkInterface, a_BlockPos + Vector3i(0, 1, -1)) || !IsNotConnected(a_ChunkInterface, a_BlockPos + Vector3i(0, 1, 0), BLOCK_FACE_NORTH, E_PURE_NONE)); + Neighbors[7] = (IsUnstable(a_ChunkInterface, a_BlockPos + Vector3i(0, 1, 1)) || !IsNotConnected(a_ChunkInterface, a_BlockPos + Vector3i(0, 1, 0), BLOCK_FACE_SOUTH, E_PURE_NONE)); + if (IsUnstable(a_ChunkInterface, a_BlockPos + Vector3i(1, -1, 0)) || !IsNotConnected(a_ChunkInterface, a_BlockPos - Vector3i(0, 1, 0), BLOCK_FACE_EAST)) { Neighbors[0] = true; } - if (IsUnstable(a_ChunkInterface, a_BlockX - 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_WEST)) + if (IsUnstable(a_ChunkInterface, a_BlockPos - Vector3i(1, 1, 0)) || !IsNotConnected(a_ChunkInterface, a_BlockPos - Vector3i(0, 1, 0), BLOCK_FACE_WEST)) { Neighbors[1] = true; } - if (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ - 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_NORTH)) + if (IsUnstable(a_ChunkInterface, a_BlockPos - Vector3i(0, 1, 1)) || !IsNotConnected(a_ChunkInterface, a_BlockPos - Vector3i(0, 1, 0), BLOCK_FACE_NORTH)) { Neighbors[2] = true; } - if (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ + 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_SOUTH)) + if (IsUnstable(a_ChunkInterface, a_BlockPos + Vector3i(0, -1, 1)) || !IsNotConnected(a_ChunkInterface, a_BlockPos - Vector3i(0, 1, 0), BLOCK_FACE_SOUTH)) { Neighbors[3] = true; } @@ -264,20 +265,20 @@ public: return m_BlockType == E_BLOCK_RAIL; } - bool IsUnstable(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + bool IsUnstable(cChunkInterface & a_ChunkInterface, Vector3i a_Pos) { - if (!IsBlockRail(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))) + if (!IsBlockRail(a_ChunkInterface.GetBlock(a_Pos))) { return false; } - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_Pos); switch (Meta) { case E_META_RAIL_ZM_ZP: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_DOWN) + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_NORTH, E_PURE_DOWN) || + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_SOUTH, E_PURE_DOWN) ) { return true; @@ -288,8 +289,8 @@ public: case E_META_RAIL_XM_XP: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST, E_PURE_DOWN) + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_EAST, E_PURE_DOWN) || + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_WEST, E_PURE_DOWN) ) { return true; @@ -300,8 +301,8 @@ public: case E_META_RAIL_ASCEND_XP: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST) + IsNotConnected(a_ChunkInterface, a_Pos + Vector3i(0, 1, 0), BLOCK_FACE_EAST) || + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_WEST) ) { return true; @@ -312,8 +313,8 @@ public: case E_META_RAIL_ASCEND_XM: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_WEST) + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_EAST) || + IsNotConnected(a_ChunkInterface, a_Pos + Vector3i(0, 1, 0), BLOCK_FACE_WEST) ) { return true; @@ -324,8 +325,8 @@ public: case E_META_RAIL_ASCEND_ZM: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) + IsNotConnected(a_ChunkInterface, a_Pos + Vector3i(0, 1, 0), BLOCK_FACE_NORTH) || + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_SOUTH) ) { return true; @@ -336,8 +337,8 @@ public: case E_META_RAIL_ASCEND_ZP: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_SOUTH) + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_NORTH) || + IsNotConnected(a_ChunkInterface, a_Pos + Vector3i(0, 1, 0), BLOCK_FACE_SOUTH) ) { return true; @@ -348,8 +349,8 @@ public: case E_META_RAIL_CURVED_ZP_XP: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_SOUTH) || + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_EAST) ) { return true; @@ -360,8 +361,8 @@ public: case E_META_RAIL_CURVED_ZP_XM: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST) + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_SOUTH) || + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_WEST) ) { return true; @@ -372,8 +373,8 @@ public: case E_META_RAIL_CURVED_ZM_XM: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST) + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_NORTH) || + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_WEST) ) { return true; @@ -384,8 +385,8 @@ public: case E_META_RAIL_CURVED_ZM_XP: { if ( - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || - IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_NORTH) || + IsNotConnected(a_ChunkInterface, a_Pos, BLOCK_FACE_EAST) ) { return true; @@ -396,31 +397,31 @@ public: return false; } - bool IsNotConnected(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, char a_Pure = 0) + bool IsNotConnected(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, eBlockFace a_BlockFace, char a_Pure = 0) { - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, false); + AddFaceDirection(a_Pos.x, a_Pos.y, a_Pos.z, a_BlockFace, false); NIBBLETYPE Meta; - if (!IsBlockRail(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))) + if (!IsBlockRail(a_ChunkInterface.GetBlock(a_Pos))) { - if (!IsBlockRail(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)) || (a_Pure != E_PURE_UPDOWN)) + if (!IsBlockRail(a_ChunkInterface.GetBlock(a_Pos + Vector3i(0, 1, 0))) || (a_Pure != E_PURE_UPDOWN)) { - if (!IsBlockRail(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)) || (a_Pure == E_PURE_NONE)) + if (!IsBlockRail(a_ChunkInterface.GetBlock(a_Pos - Vector3i(0, 1, 0))) || (a_Pure == E_PURE_NONE)) { return true; } else { - Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); + Meta = a_ChunkInterface.GetBlockMeta(a_Pos - Vector3i(0, 1, 0)); } } else { - Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY + 1, a_BlockZ); + Meta = a_ChunkInterface.GetBlockMeta(a_Pos + Vector3i(0, 1, 0)); } } else { - Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + Meta = a_ChunkInterface.GetBlockMeta(a_Pos); } switch (a_BlockFace) diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index 9dc24e039..e42f63c3b 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -32,7 +32,7 @@ public: virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f)); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}) + 0x04) & 0x0f)); return true; } diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index a424ae073..46e0a8244 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -75,7 +75,7 @@ public: // Check if the block at the coordinates is a single slab. Eligibility for combining has already been processed in ClientHandle // Changed to-be-placed to a double slab if we are clicking on a single slab, as opposed to placing one for the first time - if (IsAnySlabType(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))) + if (IsAnySlabType(a_ChunkInterface.GetBlock({a_BlockX, a_BlockY, a_BlockZ}))) { a_BlockType = GetDoubleSlabType(m_BlockType); a_BlockMeta = a_BlockMeta & 0x7; @@ -184,7 +184,7 @@ public: } } - virtual bool IsInsideBlock(const Vector3d & a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) override + virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) override { if (a_BlockMeta & 0x8) // top half { diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h index b631aae98..8e4083b0e 100644 --- a/src/Blocks/BlockSnow.h +++ b/src/Blocks/BlockSnow.h @@ -32,7 +32,7 @@ public: BLOCKTYPE BlockBeforePlacement; NIBBLETYPE MetaBeforePlacement; - a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockBeforePlacement, MetaBeforePlacement); + a_ChunkInterface.GetBlockTypeMeta({a_BlockX, a_BlockY, a_BlockZ}, BlockBeforePlacement, MetaBeforePlacement); if ((BlockBeforePlacement == E_BLOCK_SNOW) && (MetaBeforePlacement < FullBlockMeta)) { @@ -50,7 +50,7 @@ public: NIBBLETYPE MetaBelow; return ( (a_BlockY > 0) && - a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY - 1, a_BlockZ, BlockBelow, MetaBelow) && + a_ChunkInterface.GetBlockTypeMeta({a_BlockX, a_BlockY - 1, a_BlockZ}, BlockBelow, MetaBelow) && CanBeOn(BlockBelow, MetaBelow) ); } @@ -99,7 +99,7 @@ public: return 14; } - virtual bool IsInsideBlock(const Vector3d & a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) override + virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) override { return a_Position.y < (cBlockInfo::GetBlockHeight(a_BlockType) * (a_BlockMeta & 0x07)); } diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h index 8920bd7c9..aa369f0cf 100644 --- a/src/Blocks/BlockTallGrass.h +++ b/src/Blocks/BlockTallGrass.h @@ -36,7 +36,7 @@ public: { if (a_CanDrop && (a_Digger != nullptr) && (a_Digger->GetEquippedWeapon().m_ItemType == E_ITEM_SHEARS)) { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}); cItems Drops; Drops.Add(m_BlockType, 1, Meta); diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index cdda2d015..8d1363a16 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -27,7 +27,7 @@ public: BLOCKTYPE Block; NIBBLETYPE Meta; AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); // Set to clicked block - a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, Meta); + a_ChunkInterface.GetBlockTypeMeta({a_BlockX, a_BlockY, a_BlockZ}, Block, Meta); if (!CanBePlacedOn(Block, Meta, a_BlockFace)) // Try to preserve original direction { @@ -152,7 +152,7 @@ public: AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face, true); BLOCKTYPE BlockInQuestion; NIBBLETYPE BlockInQuestionMeta; - a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockInQuestion, BlockInQuestionMeta); + a_ChunkInterface.GetBlockTypeMeta({a_BlockX, a_BlockY, a_BlockZ}, BlockInQuestion, BlockInQuestionMeta); if (CanBePlacedOn(BlockInQuestion, BlockInQuestionMeta, Face)) { diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index f76d10363..b3703299f 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -37,7 +37,7 @@ public: } // Flip the ON bit on / off using the XOR bitwise operation - NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); + NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}) ^ 0x04); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); a_WorldInterface.GetBroadcastManager().BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_FENCE_GATE_OPEN, a_BlockX, a_BlockY, a_BlockZ, 0, a_Player.GetClientHandle()); diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index eae9f7fd5..f5716c58a 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -25,7 +25,7 @@ public: // TODO: Disallow placement where the vine doesn't attach to something properly BLOCKTYPE BlockType = 0; NIBBLETYPE BlockMeta; - a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); + a_ChunkInterface.GetBlockTypeMeta({a_BlockX, a_BlockY, a_BlockZ}, BlockType, BlockMeta); if (BlockType == m_BlockType) { a_BlockMeta = BlockMeta | DirectionToMetaData(a_BlockFace); @@ -109,16 +109,16 @@ public: { 1, 0, 8}, // east, XP } ; NIBBLETYPE res = 0; - for (size_t i = 0; i < ARRAYCOUNT(Coords); i++) + for (auto & Coord : Coords) { BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; if ( - a_Chunk.UnboundedRelGetBlock(a_RelX + Coords[i].x, a_RelY, a_RelZ + Coords[i].z, BlockType, BlockMeta) && + a_Chunk.UnboundedRelGetBlock(a_RelX + Coord.x, a_RelY, a_RelZ + Coord.z, BlockType, BlockMeta) && IsBlockAttachable(BlockType) ) { - res |= Coords[i].Bit; + res |= Coord.Bit; } } return res; diff --git a/src/Blocks/BlockWallSign.h b/src/Blocks/BlockWallSign.h index 7166f8ecd..c824bda11 100644 --- a/src/Blocks/BlockWallSign.h +++ b/src/Blocks/BlockWallSign.h @@ -29,7 +29,7 @@ public: int BlockX = (a_Chunk.GetPosX() * cChunkDef::Width) + a_RelX; int BlockZ = (a_Chunk.GetPosZ() * cChunkDef::Width) + a_RelZ; GetBlockCoordsBehindTheSign(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ), BlockX, BlockZ); - BLOCKTYPE Type = a_ChunkInterface.GetBlock(BlockX, a_RelY, BlockZ); + BLOCKTYPE Type = a_ChunkInterface.GetBlock({BlockX, a_RelY, BlockZ}); return ((Type == E_BLOCK_WALLSIGN) || (Type == E_BLOCK_SIGN_POST) || cBlockInfo::IsSolid(Type)); } diff --git a/src/Blocks/ChunkInterface.cpp b/src/Blocks/ChunkInterface.cpp index 1f2a97d08..44119a0d8 100644 --- a/src/Blocks/ChunkInterface.cpp +++ b/src/Blocks/ChunkInterface.cpp @@ -10,28 +10,18 @@ - -BLOCKTYPE cChunkInterface::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - return m_ChunkMap->GetBlock(a_BlockX, a_BlockY, a_BlockZ); -} - - - - - -BLOCKTYPE cChunkInterface::GetBlock(const Vector3i & a_Pos) +BLOCKTYPE cChunkInterface::GetBlock(Vector3i a_Pos) { - return GetBlock(a_Pos.x, a_Pos.y, a_Pos.z); + return m_ChunkMap->GetBlock(a_Pos.x, a_Pos.y, a_Pos.z); } -NIBBLETYPE cChunkInterface::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ) +NIBBLETYPE cChunkInterface::GetBlockMeta(Vector3i a_Pos) { - return m_ChunkMap->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + return m_ChunkMap->GetBlockMeta(a_Pos.x, a_Pos.y, a_Pos.z); } @@ -39,9 +29,9 @@ NIBBLETYPE cChunkInterface::GetBlockMeta(int a_BlockX, int a_BlockY, int a_Block -bool cChunkInterface::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) +bool cChunkInterface::GetBlockTypeMeta(Vector3i a_Pos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { - return m_ChunkMap->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + return m_ChunkMap->GetBlockTypeMeta(a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta); } @@ -125,7 +115,7 @@ bool cChunkInterface::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a bool cChunkInterface::DigBlock(cWorldInterface & a_WorldInterface, int a_X, int a_Y, int a_Z) { - cBlockHandler * Handler = cBlockInfo::GetHandler(GetBlock(a_X, a_Y, a_Z)); + cBlockHandler * Handler = cBlockInfo::GetHandler(GetBlock({a_X, a_Y, a_Z})); Handler->OnDestroyed(*this, a_WorldInterface, a_X, a_Y, a_Z); return m_ChunkMap->DigBlock(a_X, a_Y, a_Z); } diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h index 6de6478f1..120ccf455 100644 --- a/src/Blocks/ChunkInterface.h +++ b/src/Blocks/ChunkInterface.h @@ -16,11 +16,10 @@ public: cChunkInterface(cChunkMap * a_ChunkMap) : m_ChunkMap(a_ChunkMap) {} - BLOCKTYPE GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ); - BLOCKTYPE GetBlock(const Vector3i & a_Pos); - NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ); + BLOCKTYPE GetBlock(Vector3i a_Pos); + NIBBLETYPE GetBlockMeta(Vector3i a_Pos); - bool GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); + bool GetBlockTypeMeta(Vector3i a_Pos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); /** Sets the block at the specified coords to the specified value. Full processing, incl. updating neighbors, is performed. diff --git a/src/ChunkDef.h b/src/ChunkDef.h index f4a0867b5..188ad33d8 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -116,15 +116,14 @@ public: inline static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition) { - int ChunkX, ChunkZ; - BlockToChunk(a_BlockPosition.x, a_BlockPosition.z, ChunkX, ChunkZ); + cChunkCoords ChunckPos = BlockToChunk(a_BlockPosition); - return {a_BlockPosition.x - ChunkX * Width, a_BlockPosition.y, a_BlockPosition.z - ChunkZ * Width}; + return {a_BlockPosition.x - ChunckPos.m_ChunkX * Width, a_BlockPosition.y, a_BlockPosition.z - ChunckPos.m_ChunkZ * Width}; } - inline static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition, int a_ChunkX, int a_ChunkZ) + inline static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition, cChunkCoords a_ChunkPos) { - return {a_BlockPosition.x - a_ChunkX * Width, a_BlockPosition.y, a_BlockPosition.z - a_ChunkZ * Width}; + return {a_BlockPosition.x - a_ChunkPos.m_ChunkX * Width, a_BlockPosition.y, a_BlockPosition.z - a_ChunkPos.m_ChunkZ * Width}; } /** Converts relative block coordinates into absolute coordinates with a known chunk location */ diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 8ed3a6056..7fb4ca1a9 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1358,7 +1358,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo BlockHandler(a_OldBlock)->OnDestroyedByPlayer(ChunkInterface, *World, *m_Player, a_BlockX, a_BlockY, a_BlockZ); World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, a_BlockX, a_BlockY, a_BlockZ, a_OldBlock, this); // This call would remove the water, placed from the ice block handler - if (!((a_OldBlock == E_BLOCK_ICE) && (ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WATER))) + if (!((a_OldBlock == E_BLOCK_ICE) && (ChunkInterface.GetBlock({a_BlockX, a_BlockY, a_BlockZ}) == E_BLOCK_WATER))) { World->DigBlock(a_BlockX, a_BlockY, a_BlockZ); } diff --git a/tests/Generating/Stubs.cpp b/tests/Generating/Stubs.cpp index 396fa15da..fb3ed5349 100644 --- a/tests/Generating/Stubs.cpp +++ b/tests/Generating/Stubs.cpp @@ -275,7 +275,7 @@ ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) -bool cBlockHandler::IsInsideBlock(const Vector3d & a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) +bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) { return true; } diff --git a/tests/LuaThreadStress/Stubs.cpp b/tests/LuaThreadStress/Stubs.cpp index 98fbf5b74..5db1c9665 100644 --- a/tests/LuaThreadStress/Stubs.cpp +++ b/tests/LuaThreadStress/Stubs.cpp @@ -275,7 +275,7 @@ ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) -bool cBlockHandler::IsInsideBlock(const Vector3d & a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) +bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) { return true; } diff --git a/tests/SchematicFileSerializer/Stubs.cpp b/tests/SchematicFileSerializer/Stubs.cpp index a0fd807fe..715e4439e 100644 --- a/tests/SchematicFileSerializer/Stubs.cpp +++ b/tests/SchematicFileSerializer/Stubs.cpp @@ -199,7 +199,7 @@ ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) -bool cBlockHandler::IsInsideBlock(const Vector3d & a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) +bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) { return true; } -- cgit v1.2.3